home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 119_01.zip / MACBIND.C < prev    next >
Text File  |  1993-06-16  |  15KB  |  430 lines

  1. /* MACBIND.C - Customized BINDINGS.C
  2.  
  3. This contains MMakMacro and MDoMacro, which build and execute macros.
  4. MMakMacro is bound to M-M and MDoMacro is bound to M-C-M. Macros are
  5. saved in spare. Written by Barry A. Dobyns. 07/25/81.
  6. Modifications Record:
  7.         07/25/81    Original implementation in MINCE 2.6 completed. [BAD].
  8.  
  9. Also, This contains the MNewDsp and MRNewDsp, which take arguments.
  10. The argument indicates how many lines to move down or up before doing
  11. a NewDsp. Without an arg, they are equivalent to a single NewDsp. I
  12. always seem to be doing a C-U nn C-N C-L or C-U nn C-P C-L and this
  13. takes care of that for me in an elegant way. Written by Barry A.
  14. Dobyns 07/22/81.
  15. Modifications Record:
  16.         07/22/81    Original implementation in MINCE 2.6 completed. [BAD].
  17.  
  18. This one has MIncSearch() and MIncRSearch() which implement
  19. incremental searches in a way halfway between Mince's  non-incremental
  20. MSearch and EMACS ^R Incremental Search. The MIncSearch gets the
  21. search argument all at once, like MSearch, and unlike ^R Incremental Search
  22. but leaves the point after the best match (the most matches from left
  23. to right for the search arg) unlike MSearch and like ^R Incremental Search.
  24. I have taken the liberty of binding them to C-R and C-S so as to
  25. replace the regular MSearch and MRsearch, since I couldn't find any other
  26. good ways to name them consistent with the current naming philosophy.
  27. MIncSearch() and MIncRSearch() written by Barry A. Dobyns 07/07/81.
  28. Modifications record:
  29.         07/07/81    Original Implementation in MINCE 2.5 completed. [BAD].
  30.         07/22/81    Bug fixes and installation in Version 2.6.
  31.                     Significant speed improvements by running under
  32.                     2.6, even with the redisplay, it is still faster
  33.                     than the old 2.5 searches alone. I strongly do not
  34.                     reccommend permanent implementation in 2.5. [BAD].
  35.         07/23/81  Renamed to MSearch and MRSearch to save space. 
  36.                 I only need one set of search commands at a time.
  37.                 Since L2 and CLINK both ignore all occurences of a
  38.                 function except for the first. With COMM1 ahead of
  39.                     the -l option on the L2 command line, we MUST name
  40.                     these guys the same as the functions they replace,
  41.                     or edit them out of either the source (before
  42.                     compilation) or the .CRL (with CLIB). I can compile
  43.                     and link this into a small -e7900 MINCE in 2.6,
  44.                     but I believe my TERM routines are a bit shorter
  45.                     overall, so you may not be able to. [BAD].
  46.         09/19/81  Renamed back to MIncSearch and MIncRSearch, since
  47.                     I have moved MSearch and MRSearch, along with all
  48.                     of the page mode functions [e.g. MP????() ] into
  49.                     COMM4.C so that they will not be linked in
  50.                     anymore. COMM4.C appears after the -l switch on
  51.                     the L2 command line. Page Mode is commented out of
  52.                     BINDINGS.C. It is tempting to put all of the
  53.                     COMMn.C files after the -l option, and not play
  54.                     musical source code anymore. [BAD].
  55. */
  56.  
  57. /* BINDINGS.C - Set up the key bindings for Mince
  58.  
  59. The seller of this software hereby disclaims any and all
  60. guarantees and warranties, both express and implied.  No
  61. liability of any form shall be assumed by the seller, nor shall
  62. direct, consequential, or other damages be assumed by the seller.
  63. Any user of this software uses it at his or her own risk.
  64.  
  65. Due to the ill-defined nature of "fitness for purpose" or similar
  66. types of guarantees for this type of product, no fitness for any
  67. purpose whatsoever is claimed or implied.
  68.  
  69. The physical medium upon which the software is supplied is
  70. guaranteed for one year against any physical defect.  If it
  71. should fail, return it to the seller, and a new physical medium
  72. with a copy of the purchased software shall be sent.
  73.  
  74. The seller reserve the right to make changes, additions, and
  75. improvements to the software at any time; no guarantee is made
  76. that future versions of the software will be compatible with any
  77. other version.
  78.  
  79. The parts of this disclaimer are severable and fault found in any
  80. one part does not invalidate any other parts.
  81.  
  82.     Copyright (c) 1981 by Mark of the Unicorn
  83.     Created for Version 2.3  10/4/80  JTL
  84.     Updated to version three  1/7/81  JTL
  85.  
  86.     This file contains the function table initializers and mode set up
  87. functions */
  88.  
  89. #include "mince.gbl"
  90.  
  91. finit1()            /* initialize the control and self insert key bindings */
  92. {
  93.     int cnt;
  94.     int MInsert(), MSetMrk(), MBegLin(), MPrevChar();
  95.     int MNotImpl(), MDelChar(), MEndLin(), MNextChar();
  96.     int MAbort(), MDelLin(), MNewDsp(), MNewLin();
  97.     int MNextLin(), MOpenLin(), MPrevLin(), MQuote();
  98.     int MIncRSearch(), MIncSearch(), MSwapChar(), MArg();
  99.     int MNextPage(), MDelRgn(), MCtrlX(), MYank();
  100.     int MMeta(), MDelIndent(), MRDelChar(), MIndent();
  101.  
  102.  
  103.     for (cnt=0; cnt<128; ++cnt) functs[cnt] = MInsert;
  104.     TKbChk();
  105.     functs[0] = MSetMrk;        /* C-@ */
  106.     functs[1] = MBegLin;        /* C-A */
  107.     functs[2] = MPrevChar;        /* C-B */
  108.     functs[3] = MNotImpl;        /* C-C */
  109.     functs[4] = MDelChar;        /* C-D */
  110.     functs[5] = MEndLin;        /* C-E */
  111.     functs[6] = MNextChar;        /* C-F */
  112.     functs[7] = MAbort;            /* C-G */
  113.     functs[8] = MPrevChar;        /* C-H */
  114.                             /* C-I */
  115.     functs[10] = MIndent;        /* C-J */
  116.     functs[11] = MDelLin;        /* C-K */
  117.     functs[12] = MNewDsp;        /* C-L */
  118.     functs[13] = MNewLin;        /* C-M */
  119.     functs[14] = MNextLin;        /* C-N */
  120.     functs[15] = MOpenLin;        /* C-O */
  121.     functs[16] = MPrevLin;        /* C-P */
  122.     functs[17] = MQuote;        /* C-Q */
  123.     functs[18] = MIncRSearch;        /* C-R */
  124.     functs[19] = MIncSearch;        /* C-S */
  125.     functs[20] = MSwapChar;        /* C-T */
  126.     functs[21] = MArg;            /* C-U */
  127.     functs[22] = MNextPage;        /* C-V */
  128.     functs[23] = MDelRgn;        /* C-W */
  129.     functs[24] = MCtrlX;        /* C-X */
  130.     functs[25] = MYank;            /* C-Y */
  131.     functs[26] = MNotImpl;        /* C-Z */
  132.     functs[ESC] = MMeta;        /* ESC */
  133.     functs[28] = MDelIndent;        /* C-\ */
  134.     functs[29] = MNotImpl;        /* C-] */
  135.     functs[30] = MNotImpl;        /* C-^ */
  136.     functs[31] = MNotImpl;        /* C-_ */
  137.     functs[DEL] = MRDelChar;        /* DEL */
  138.     }
  139.  
  140. finit2()            /* set up the Meta key bindings */
  141. {
  142.     int cnt;
  143.     int MNotImpl(), MAbort(), MDelELin(), MRNewDsp(); 
  144.     int MDoMacro(), MQryRplc();
  145.     int MMakeDel(), MToStart(), MToEnd(), MBSent();
  146.     int BWord(), MCapWord(), MDelWord(), MFSent();
  147.     int FWord(), MMrkPara(), MDelSent(), MLowWord();
  148.     int MMakMacro(), MFillPara(), MReplace(), MCntrLine(), MUpWord();
  149.     int MPrevPage(), MCopyRgn(), MBPara(), MDelWhite();
  150.     int MFPara(), MRDelWord(), MSetMrk(), MSwapWord();
  151.  
  152.     for (cnt=128; cnt<256; ++cnt) functs[cnt] = MNotImpl;
  153.     TKbChk();
  154.     functs[128+7] = MAbort;                    /* M-C-G */
  155.     functs[128+8] = MRDelWord;                /* M-C-H */
  156.     functs[128+11] = MDelELin;                /* M-C-K */
  157.     functs[128+12] = MRNewDsp;                /* M-C-L */
  158.     functs[128+13] = MDoMacro;                /* M-C-M */
  159.     functs[128+18] = MQryRplc;                /* M-C-R */
  160.     functs[128+23] = MMakeDel;                /* M-C-W */
  161.     functs[128+'<'] = MToStart;                /* M-< */
  162.     functs[128+'>'] = MToEnd;                /* M-> */
  163.     functs[128+' '] = MSetMrk;                /* M-  */
  164.     functs[128+'A']=functs[128+'a'] = MBSent;    /* M-A */
  165.     functs[128+'B']=functs[128+'b'] = BWord;    /* M-B */
  166.     functs[128+'C']=functs[128+'c'] = MCapWord;    /* M-C */
  167.     functs[128+'D']=functs[128+'d'] = MDelWord;    /* M-D */
  168.     functs[128+'E']=functs[128+'e'] = MFSent;    /* M-E */
  169.     functs[128+'F']=functs[128+'f'] = FWord;    /* M-F */
  170.     functs[128+'H']=functs[128+'h'] = MMrkPara;    /* M-H */
  171.     functs[128+'K']=functs[128+'k'] = MDelSent;    /* M-K */
  172.     functs[128+'L']=functs[128+'l'] = MLowWord;    /* M-L */
  173.     functs[128+'M']=functs[128+'m'] = MMakMacro;    /* M-M */
  174.     functs[128+'Q']=functs[128+'q'] = MFillPara;    /* M-Q */
  175.     functs[128+'R']=functs[128+'r'] = MReplace;    /* M-R */
  176.     functs[128+'S']=functs[128+'s'] = MCntrLine;    /* M-S */
  177.     functs[128+'T']=functs[128+'t'] = MSwapWord;    /* M-T */
  178.     functs[128+'U']=functs[128+'u'] = MUpWord;    /* M-U */
  179.     functs[128+'V']=functs[128+'v'] = MPrevPage;    /* M-V */
  180.     functs[128+'W']=functs[128+'w'] = MCopyRgn;    /* M-W */
  181.     functs[128+'['] = MBPara;                /* M-[ */
  182.     functs[128+'\\'] = MDelWhite;                /* M-\ */
  183.     functs[128+']'] = MFPara;                /* M-] */
  184.     functs[128+DEL] = MRDelWord;                /* M-DEL */
  185.     }
  186.  
  187. finit3()            /* set up the Control-X key bindings */
  188. {
  189.     int cnt;
  190.     int MNotImpl(), MLstBuffs(), MExit(), MFindFile();
  191.     int MAbort(), MSetTabs(), MDelMode(), MFileRead();
  192.     int MFileSave(), MFileWrite(), MSwapMrk(), MSetIndent();
  193.     int MPrintPos(), MSwitchTo(), MKillBuff(), MSetFill();
  194.     int MAddMode(), MOneWind(), MTwoWind(), MSwpWind();
  195.     int MNxtOthrWind(), MPrvOthrWind(), MGrowWind();
  196. #ifdef UNIX
  197.     int MUnix();
  198. #endif
  199.  
  200.     for (cnt=256; cnt<384; ++cnt) functs[cnt] = &MNotImpl;
  201.     TKbChk();
  202.     functs[256+2] = MLstBuffs;                /* C-X C-B */
  203.     functs[256+3] = MExit;                    /* C-X C-C */
  204.     functs[256+6] = MFindFile;                /* C-X C-F */
  205.     functs[256+7] = MAbort;                    /* C-X C-G */
  206.     functs[256+9] = MSetTabs;                /* C-X Tab */
  207.     functs[256+13] = MDelMode;                /* C-X C-M */
  208.     functs[256+18] = MFileRead;                /* C-X C-R */
  209.     functs[256+19] = MFileSave;                /* C-X C-S */
  210.     functs[256+22] = MNxtOthrWind;            /* C-X C-V */
  211.     functs[256+23] = MFileWrite;                /* C-X C-W */
  212.     functs[256+24] = MSwapMrk;                /* C-X C-X */
  213.     functs[256+26] = MPrvOthrWind;            /* C-X C-Z */
  214.     functs[256+'.'] = MSetIndent;                /* C-X . */
  215. #ifdef UNIX
  216.     functs[256+'!'] = MUnix;                    /* C-X ! */
  217. #endif
  218.     functs[256+'='] = MPrintPos;                /* C-X = */
  219.     functs[256+'1'] = MOneWind;                /* C-X 1 */
  220.     functs[256+'2'] = MTwoWind;                /* C-X 2 */
  221.     functs[256+'B']=functs[256+'b'] = MSwitchTo;    /* C-X B */
  222.     functs[256+'K']=functs[256+'k'] = MKillBuff;    /* C-X K */
  223.     functs[256+'F']=functs[256+'f'] = MSetFill;    /* C-X F */
  224.     functs[256+'M']=functs[256+'m'] = MAddMode;    /* C-X M */
  225.     functs[256+'O']=functs[256+'o'] = MSwpWind;    /* C-X O */
  226.     functs[256+'^'] = MGrowWind;                /* C-X ^ */
  227.     }
  228.  
  229. SetModes()            /* Set the modes according to the bmodes array */
  230. {
  231.     int cnt;
  232.     int MFillChk();
  233. /*    These are for the (unnecessary) page mode
  234.     int MOverwrite(), MPBegLine(), MInsert();
  235.     int MPBChar(), MPEndLine(), MPFChar(), MPBackSpace();
  236.     int MPNextLine(), MPPrevLine(), MTrimWhite(), MPTab(); */
  237. #ifdef LARGE
  238.     int MNewLin(), MCIndent(), MSInsert();
  239. #endif
  240.  
  241.     *mode='\0';
  242.     finit1();                    /* Set up the key bindings */
  243.     finit2();
  244.     finit3();
  245.     for (cnt=MAXMODES-1; cnt>=0; --cnt) {
  246.         switch (buffs[cbuff].bmodes[cnt]) {
  247.  
  248. #ifdef LARGE
  249.         case 'c':
  250.             functs[13] = MCIndent;
  251.             strcat(mode,"C ");
  252.             break;
  253.         case 's':
  254.             Rebind(MInsert,MSInsert);
  255.             strcat(mode,"Save ");
  256.             break;
  257. #endif
  258.         case 'f':
  259.             functs[' '] = MFillChk;
  260.             strcat(mode,"Fill ");
  261.             break;
  262. /*        case 'p':
  263.             Rebind(MInsert,MOverwrite);
  264.             functs[1] = MPBegLine;
  265.             functs[2] = MPBChar;
  266.             functs[5] = MPEndLine;
  267.             functs[6] = MPFChar;
  268.             functs[8] = MPBackSpace;
  269.             functs[9] = MPTab;
  270.             functs[14] = MPNextLine;
  271.             functs[16] = MPPrevLine;
  272.             functs[256+'\\'] = MTrimWhite;
  273.             strcat(mode,"Page ");
  274.             break;    */
  275.             }
  276.         }
  277.     if (!*mode) strcpy(mode,"Normal ");
  278.     mode[strlen(mode)-1]='\0';
  279.     ModeLine();
  280.     }
  281.  
  282. UInit()                /* Do user code initilization */
  283.     /* This function is called once at the very begining. It may be used
  284.     to do any initilization required for user code */
  285. {
  286.     }
  287.  
  288. MIncSearch()        /* Forward Incremental String Search */
  289. {
  290.     int tmp,cnt;
  291.     if (!GetArg("Incremental Search <ESC>: ",ESC,strarg,STRMAX)){
  292.         arg=0;
  293.         return;
  294.         }
  295.     for (cnt = 0; strarg[cnt] != '\0'; cnt++){
  296.         tmp = strarg[cnt + 1];    /* save the char */
  297.         strarg[cnt + 1] = '\0';    /* and truncate srtarg to length I */
  298.         tmark = BCreMrk();        /* Current point */ 
  299.         if (!StrSrch(strarg,FORWARD)){
  300.             BPntToMrk(tmark);
  301.             BMove(cnt);        /* Put point after last found chars */
  302.             Echo ("Not Found");
  303.             arg=0;
  304.             return;
  305.             }
  306.         strarg[cnt + 1] = tmp;    /* restore strarg */
  307.         IncrDsp();            /* force redisplay */
  308.         BMove(-cnt - 1);        /* get before the truncated strarg 
  309.                                so that if this is the complete
  310.                                strarg we will find it */
  311.         BKillMrk(tmark);
  312.         }
  313.     Bmove(cnt);                /* Put point after last found chars */
  314.     }
  315.  
  316. MIncRSearch()        /* Reverse Incremental String Search */
  317. {
  318.     int tmp,cnt;
  319.     if (!GetArg("Reverse Incremental Search <ESC>: ",ESC,strarg,STRMAX)){
  320.         arg=0;
  321.         return;
  322.         }
  323.     for (cnt = 1; strarg[cnt] != '\0'; cnt++){
  324.         tmp = strarg[cnt + 1];    /* save the char */
  325.         strarg[cnt + 1] = '\0';    /* and truncate srtarg to length I */
  326.         tmark = BCreMrk();        /* Current point */ 
  327.         if (!StrSrch(strarg,BACKWARD)){
  328.             BPntToMrk(tmark);
  329.             BMove(-cnt);        /* Put point after last found chars */
  330.             Echo ("Not Found");
  331.             arg=0;
  332.             return;
  333.             }
  334.         strarg[cnt + 1] = tmp;    /* restore strarg */
  335.         IncrDsp();            /* force redisplay */
  336.         BMove(cnt + 1);        /* get before the truncated strarg 
  337.                                so that if this is the complete
  338.                                strarg we will find it */
  339.         BKillMrk(tmark);
  340.         }
  341.     BMove(-cnt);                /* Put point after last found chars */
  342.     }
  343.  
  344. MNewDsp()            /* move down arg lines and redisplay*/
  345. {
  346.     if (argp){
  347.         if (!VMovCmnd(lfunct)) lcol=BGetCol();
  348.         while(arg-- > 0) NLSrch();
  349.         BMakeCol(lcol);
  350.         }
  351.     arg=0;
  352.     NewDsp();
  353.     }
  354.  
  355. MRNewDsp()            /* move arg lines previous and redisplay */
  356. {
  357.     if (argp){
  358.         if (!VMovCmnd(lfunct)) lcol=BGetCol();
  359.         while (arg-- > 0) RNLSrch();
  360.         BMakeCol(lcol);
  361.         }
  362.     arg = 0;
  363.     NewDsp();
  364.     }
  365.  
  366. MMakMacro()
  367. {
  368.     char *macroptr;
  369.  
  370.     macroptr = spare;
  371.     GetMacro("Macro <C-^>:",'\035',strarg,20);
  372.     strcpy(macroptr,strarg);
  373.     Echo(macroptr);
  374.     }
  375.  
  376. MDoMacro()
  377. {
  378.     char *macroptr;
  379.     
  380.     macroptr = spare;
  381.     TSetPoint(TMaxRow()-1,0);
  382.     while (*macroptr != '\0'){
  383.         TPrntChar(*macroptr);
  384.         if (!QFull(&kbdq)) QShove(*macroptr, &kbdq);
  385.         else TBell();
  386.         macroptr++;
  387.         }
  388.     }
  389.  
  390. GetMacro(mesg,term,str,len)    /* input a string argument */
  391.     char *mesg, term, *str;
  392.     int len;
  393. {
  394.     char stemp[80], inpt, *nstr, tcol;
  395.  
  396.     TDisStr(TMaxRow()-1,0,mesg);
  397.     TCLEOL();
  398.     tcol=TGetCol();
  399.     TForce();
  400.     nstr=stemp;
  401.     while ((KbWait(),inpt=TGetKb())!=term) {
  402.         if (inpt==BELL) {
  403.             ClrEcho();
  404.             return(FALSE);
  405.             }
  406.         switch (inpt) {
  407.             case CR:
  408.                 TPrntStr("<NL>");
  409.                 *nstr++=NL;
  410.                 break;
  411.             default:
  412.                 TPrntChar(inpt);
  413.                 *nstr++=inpt;
  414.                 break;
  415.             }
  416.         TForce();
  417.         }
  418.     if (nstr!=stemp) {
  419.         *nstr='\0';
  420.         strcpy(str,stemp);
  421.         }
  422.     else NLPrnt(str);
  423.     TSetPoint(TMaxRow()-1,0);
  424.     TForce();
  425.     return(TRUE);
  426.     }
  427.  
  428. /* END OF BINDINGS.C - set up key bindings */
  429. ;
  430.     GetMacro("Macro <C-^>:",'\035',stra